package com.young.springdemo.controller.delay;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.DelayQueue;
import java.util.concurrent.TimeUnit;

/**
 * @program: springdemo
 * @description
 * @author: Young
 * @create: 2020-08-08 15:44
 **/
@Slf4j
public class TestMain {
    public static void main(String[] args) throws Exception{
        Stuedent xiaoming = new Stuedent("小明",12,"南京");
        Stuedent xiaohong = new Stuedent("小红",15,"北京");
        DelayEntity xiaomingD = new DelayEntity(xiaoming,5000, TimeUnit.MILLISECONDS);
        DelayEntity xiaoHongD = new DelayEntity(xiaohong,1000,TimeUnit.MILLISECONDS);
        DelayQueue<DelayEntity> queue = new DelayQueue<>();
        queue.put(xiaoHongD);
        queue.put(xiaomingD);
        while (true){
            if(queue.size()>0){
                DelayEntity poll = queue.take();
                log.info("poll : [{}]",poll.getStudent().toString());
            }else {
                break;
            }
        }
    }
}
